@extends('layouts.back_stage')
@section('content')
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;"><h3 style="float:left;">生产商品单列表</h3></div>
        <form action="">
            <div class="flow_head_box">
                <label>品牌</label>
                <select class="address" name="brand_id" style="width: 150px">
                    @if(isset($_GET['brand_id']) && $_GET['brand_id'] )
                        <option value="{{ $_GET['brand_id'] }}">{{ $brands[$_GET['brand_id']] }}</option>
                    @else
                        <option value="">请选择</option>
                    @endif

                    @foreach($brands as $k=>$v)
                        <option value="{{ $k }}">{{ $v }}</option>
                    @endforeach
                </select>
                <label>款号</label>
                <input type="text" style="width: 150px;display: inline-block;" name="girard" value="" class="form-control" placeholder="输入款号">
                <input class="btn btn-info" style="margin-bottom:3px;" type="submit" value="搜索" >
                <a class="btn btn-primary" style="float:right;margin-right:30px" href="/production/create">添加生产商品</a>
            </div>
        </form>
        <span style="display:none;" class="info_sum">{{$goods_count}}</span>
        <table class="table" style="margin-top: 20px;">
            <thead>
            <tr>
                <th>款号</th>
                <th>品牌</th>
                <th>类目一</th>
                <th>类目二</th>
                <th>类目三</th>
                <th>颜色</th>
                <th>手数</th>
                <th>件数</th>
                <th>&nbsp;&nbsp;&nbsp;&nbsp;操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $key =>$goods)
                <tr>
                    <td> {{ $goods->item }}</td>
                    <td> {{ $attr['brand_name'][$key] }}</td>
                    <td> {{ $attr['category_one'][$key] }}</td>
                    <td> {{ $attr['category_two'][$key] }}</td>
                    <td> {{ $attr['category_three'][$key] }}</td>
                    <td> {{ $goods->color }}</td>
                    <td> {{ $goods->num }}</td>
                    <td> {{ $goods->total }}</td>
                    <td>
                        @if($goods->is_generate == 0)
                            <button id='generate_{{$goods->id}}' class="btn btn-primary" onclick="codeGenerate({{$goods->id}},{{$goods->num}})">
                                生成二维码
                            </button>
                            <a  class="btn btn-info" href="/production/edit?id={{$goods->id}}">
                                编辑
                            </a>
                        @else
                            <button class="btn btn-success" disabled="true">已生成二维码</button>
                            <a class="btn btn-info" href="/production/check?id={{$goods->id}}">查看</a>

                        @endif
                        <button class="btn btn-danger" onclick="deleteGoods({{ $goods->id }})">删除</button>
                        @if($goods->is_generate == 1 && $goods->is_signature == 0)
                            <button class="btn btn-primary" onclick="signature({{ $goods->id }})">贴码</button>
                        @elseif($goods->is_generate == 1 && $goods->is_signature == 1)
                            <button class="btn btn-primary" disabled="true">已贴码</button>
                        @endif

                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div style="float: right"><div style="float: right;margin:20px 0;"><button class="btn btn-info" onclick="returnPage()" style="float:right;">跳转</button><input type="text" class="form-control returnPage" style="width:6rem;float: right;margin:0 5px;"></div>{{ $data->appends(['girard'=>$girard,'brand_id'=>$brand_id])->links() }}</div>
    </div>
    <script>
        function deleteGoods(id) {
            $(".oText").text("确认要删除吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','oRefund');
            $(document).on('click','#oRefund',function(){
                $(".oMask").hide();
                $(".oAnim").hide();
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    type:'post',
                    url:'/production/delete',
                    data:{
                        'id':id
                    },
                    success:function (data) {
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("删除成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }
                });
            });
        }
        function codeGenerate(id,num) {
            $('#generate_'+id).attr('disabled',true);
            $.ajax({
//                headers: {
//                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
//                },
                type:'post',
                url:"{{env('UPLOAD_IMG_DOMAIN')}}/production/code-generate",
                data:{
                    'id':id,
                    'num':num,
                    'uid':'{{ \Illuminate\Support\Facades\Auth::guard('admin')->user()->id }}'
                },
                success:function (data) {
                    window.location.href ='/production/check?id='+id;
                }
            })
        }
        function signature(id) {
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/production/signature',
                data:{
                    'id':id
                },
                dataType:'json',
                success:function (data) {
                    $(".faceImg").attr("src","/img/laugh.png");
                    $(".oHandle").text("贴码成功");
                    $(".oSuccess").show(0).delay(1000).hide(0);
                    window.location.reload();
                }
            })
        }
    </script>
@endsection